﻿#ifndef HEADERCOMMACRO_H
#define HEADERCOMMACRO_H

#if 1
#include <QtGlobal>
#else
/*
   Some classes do not permit copies to be made of an object. These
   classes contains a private copy constructor and assignment
   operator to disable copying (the compiler gives an error message).
*/
#ifndef Q_DISABLE_COPY
#define Q_DISABLE_COPY(Class) \
    Class(const Class &) = delete;\
    Class & operator=(const Class &) = delete;
#endif

template <typename T> static inline T * qGetPtrHelper(T * ptr) { return ptr; }
template <typename Wrapper> static inline typename Wrapper::pointer qGetPtrHelper(const Wrapper & p) { return p.data(); }

#define Q_DECLARE_PRIVATE(Class) \
    inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(qGetPtrHelper(d_ptr)); } \
    inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(qGetPtrHelper(d_ptr)); } \
    friend class Class##Private

#define Q_DECLARE_PRIVATE_D(Dptr, Class) \
    inline Class##Private* d_func() { return reinterpret_cast<Class##Private *>(Dptr); } \
    inline const Class##Private* d_func() const { return reinterpret_cast<const Class##Private *>(Dptr); } \
    friend class Class##Private

#define Q_DECLARE_PUBLIC(Class)                                    \
    inline Class* q_func() { return static_cast<Class *>(q_ptr); } \
    inline const Class* q_func() const { return static_cast<const Class *>(q_ptr); } \
    friend class Class

#define Q_D(Class) Class##Private * const d = d_func()
#define Q_Q(Class) Class * const q = q_func()

#endif

// 单例模式宏
#define SINGLETON(_CLASS_)                \
public:                                   \
    inline static _CLASS_ & getInstance() \
    {                                     \
        static _CLASS_ sInstance;         \
        return sInstance;                 \
    }                                     \
                                          \
protected:                                \
    _CLASS_();                            \
    virtual ~_CLASS_();                   \
    Q_DISABLE_COPY(_CLASS_)


//单例模式默认构造函数与析构函数（配合单例模式宏使用）
#define SINGLETON_C_D(_CLASS_)      \
    _CLASS_::_CLASS_(){}            \
    _CLASS_::~_CLASS_(){}           \

#endif  // HEADERCOMMACRO_H
